<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../resources/tmpl/catalog_layout.xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="content">
        <h:form id="form-content">            
            <p:growl id="growl-content" life="3000" />
            <p:panel id="panel-content" header="#{messages.panelTitle} #{years.entityName}">
                <p:panelGrid columns="1" style="width: 100%">
                    <p:toolbar id="toolbar-content">
                        <p:toolbarGroup align="left">
                            <p:button title="#{messages.homeButton}" icon="ui-icon-home" outcome="list" />
                        </p:toolbarGroup>
                        <p:toolbarGroup align="right">                        
                            <p:commandButton title="#{messages.newButton}" icon="ui-icon-document" actionListener="#{years.newEvent(event)}" oncomplete="dlg.show()" 
                                             update=":dialog-content" />
                            <p:commandButton title="#{messages.editButton}" icon="ui-icon-pencil" actionListener="#{years.editEvent(event)}" oncomplete="dlg.show()" 
                                             disabled="#{years.disableButtons}" update=":dialog-content" />
                            <p:commandButton title="#{messages.deleteButton}" icon="ui-icon-trash" actionListener="#{years.remove(event)}"
                                             disabled="#{years.disableButtons}" update=":form-content" /> 
                        </p:toolbarGroup>
                    </p:toolbar>
                    <hr/>
                    <p:dataTable id="data-table-content" var="year" value="#{years.selectable}" selection="#{years.selected}"
                                 selectionMode="single" paginator="true" rows="10" emptyMessage="#{messages.noData}">

                        <p:ajax event="rowSelect" listener="#{years.onRowSelect}" update=":form-content" />
                        <p:ajax event="rowDblselect" listener="#{years.onDblSelect}" update=":form-content" />

                        <p:column filterBy="#{year.year}" headerText="#{messages.yearColumn}" sortBy="#{year.year}">
                            <h:outputText value="#{year.year}" />
                        </p:column>

                        <p:column headerText="#{messages.descriptionColumn}">                    
                            <h:outputText value="#{year.description}" />
                        </p:column>  
                    </p:dataTable>
                </p:panelGrid>
            </p:panel>
        </h:form>
        <p:dialog id="dialog-content" header="#{years.titleDialog}" widgetVar="dlg" modal="true" closable="false">
            <h:form id="form-dialog-content">
                <p:panelGrid>
                    <p:row>
                        <p:column>
                            <p:outputLabel for="year" value="#{messages.yearColumn}:"/>
                        </p:column>
                        <p:column>
                            <p:spinner id="year" value="#{years.selected.year}" min="1" max="100" required="true" />
                        </p:column>
                    </p:row>
                    <p:row>
                        <p:column>
                            <p:outputLabel for="description" value="#{messages.descriptionColumn}:" />
                        </p:column>
                        <p:column>
                            <p:inputTextarea id="description" value="#{years.selected.description}" />
                        </p:column>
                    </p:row>
                    <p:row>
                        <p:column colspan="2">
                            <p:commandButton value="#{messages.saveButton}" icon="ui-icon-disk" action="#{years.edit(event)}" 
                                             update=":form-content" oncomplete="handleDialogRequest(xhr, status, args)" />
                            <p:button value="#{messages.cancelButton}" icon="ui-icon-close" outcome="years" />                                        
                        </p:column>
                    </p:row>
                </p:panelGrid>                
            </h:form>
        </p:dialog>
    </ui:define>

</ui:composition>
